package com.example.demo1122.controller;


import com.example.demo1122.domain.ResponseResult;
import com.example.demo1122.entity.Conversation;
import com.example.demo1122.service.IChapterService;
import com.example.demo1122.service.IClassService;
import com.example.demo1122.service.IConversationService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2023-12-11
 */
@Controller
@RequestMapping("/class")
public class ClassController {
    @Resource
    private IChapterService chapterService;
    @Resource
    private IConversationService conversationService;
    @Resource
    private IClassService classService;

    // 返回一个课堂中的所有章节信息
    @PostMapping("/chapterinfo/{classID}")
    @ResponseBody
    public ResponseResult showChapter(@PathVariable Integer classID){
        if (classID == null){
            return new ResponseResult(0, "error", "未获取到classID");
        }
        return chapterService.showChapter(classID);
    }

    // 返回一个课堂中的所有会话信息
    @PostMapping("/showclassconversation/{classID}")
    @ResponseBody
    public ResponseResult showClassConversation(@PathVariable Integer classID){
        if (classID == null){
            return new ResponseResult(0, "error", "未获取到classID");
        }
        return conversationService.showClassConversation(classID);
    }

    // 教师模糊搜索会话列表
    @PostMapping("/searchconversation")
    @ResponseBody
    public ResponseResult searchConversation(@RequestBody Conversation conversation){
        return conversationService.searchConversation(conversation);
    }

    @PostMapping("/classinfo/{classID}")
    @ResponseBody
    public ResponseResult classInfo(@PathVariable Integer classID){
        if (classID == null){
            return new ResponseResult(0, "error", "未获取到classID");
        }
        return classService.classInfo(classID);
    }

    // 返回某一时间段内该课堂的会话数量
    @GetMapping("/getConversationNum")
    @ResponseBody
    public ResponseResult getClassConversationNum_interval(@RequestParam Integer classID,
                                                      @RequestParam(required = false) Integer chapterID,
                                                      @RequestParam(required = false) Integer interval){
        return conversationService.getClassConversationNum_interval(classID, chapterID, interval);
    }

    // 返回某一时间段内该课堂的会话数量
    @GetMapping("/getConversationNumRange")
    @ResponseBody
    public ResponseResult getClassConversationNum_range(@RequestParam Integer classID,
                                                        @RequestParam(required = false) Integer chapterID,
                                                        @RequestParam String startSelectTime,
                                                        @RequestParam String endSelectTime){
        return conversationService.getClassConversationNum_range(classID, chapterID, startSelectTime, endSelectTime);
    }
}
